package extract;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class SysCostExtractor {
	public static final String SEPERATOR = "\t";

	public static void main(String[] args) throws IOException {
		DataInputStream dis = new DataInputStream(new FileInputStream(args[0]));
		DataOutputStream dos = new DataOutputStream(new FileOutputStream(
				args[1]));
		String line = null;
		try {
			boolean start = false;
			int count = 1;
			while (null != (line = dis.readLine())) {
				StringBuffer buffer = new StringBuffer();
				if (start) {
					String[] fields = line.split("     ");
					buffer.append(count);
					for (String field : fields) {
						buffer.append(SEPERATOR);
						buffer.append(field);
					}
				} else {
					if (line.contains("all")) {
						start = true;
						String[] fields = line.split("     ");
						buffer.append(count);
						for (String field : fields) {
							buffer.append(SEPERATOR);
							buffer.append(field);
						}
					}
				}
				if (buffer.length() > 0) {
					buffer.append("\n");
					dos.write(buffer.toString().getBytes());
					count++;
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			dis.close();
			dos.close();
		}
	}
}
